
local charmap = require "barf.rcr.charmap"
local gsub, strbyte, strchar
    = string.gsub, string.byte, string.char
local pairs, error
    = pairs, error
local wx = require "wx"
    
require 'barf.rcr.addresses'
    

module "barf.rcr"


function decodestring(str)
    -- extra parentheses to truncate to first value
    return (gsub(str, '.', function(c)  return charmap[strbyte(c)] or '?';  end))
end

local reverse_charmap = {}
local valid_char_array = {}

for k,v in pairs(charmap) do
    reverse_charmap[v] = strchar(k)
    valid_char_array[#valid_char_array+1] = v
end

function encodestring(str)
    -- extra parentheses to truncate to first value
    return (gsub(str, '.', function(c)  return reverse_charmap[c] or error('invalid character');  end))
end

textvalidator = wx.wxTextValidator(wx.wxFILTER_INCLUDE_CHAR_LIST);
textvalidator.Includes = valid_char_array;
